import { defineStore } from "pinia"
import { getTeamWorksData, getMyTaskData,bulkForwardWorks } from "@/api/modules/task.js"
import { uploadWorks } from "@/api/modules/task.js"
import { ElMessage, ElLoading } from 'element-plus'
export const worksData = defineStore("worksData", {
    state: () => {
        return {
            teamsWorksdata: [],
            count: 0,
            myTeamWorksdata: []
        }
    },
    actions: {


        // 获取团队任务中的数据
        async getWorksData(data) {

            const loading = ElLoading.service({
                lock: true,
                text: 'Loading',
                background: 'rgba(0, 0, 0, 0.7)',
            })

            try {
                // console.log(data)
                let res = await getTeamWorksData(data)
                // console.log(res, "resData")
                this.teamsWorksdata = res.data
                this.count = res.count
            } finally {
                setTimeout(() => {
                    loading.close()
                }, 700);
            }
        },

        // 获取个人的任务数据
        async getOwnTaskData(data) {

            const loading = ElLoading.service({
                lock: true,
                text: 'Loading',
                background: 'rgba(0, 0, 0, 0.7)',
            })
            try {
                // console.log(data, "data")
                let res = await getMyTaskData(data)
                this.myTeamWorksdata = res.data
                this.count = res.count
                // console.log(res)
            } finally {
                setTimeout(() => {
                    loading.close()
                }, 600);
            }
        },

         // 上传作品测试
         async userUplaodWorksData(data){
            // console.log(data,"我是仓库里面的数据")
            let res = await uploadWorks(data)
            // console.log(res)
            if(res.code==200){
                // console.log(res)
                return "ok"
            }else{
                return "faile"
            }
        },

        // 批量转交任务
        async bulkForwardWorkDatas(data){
            // console.log(data,"仓库里面的数据")
            let res = await bulkForwardWorks(data)
            // console.log(res,"返回结果")
        }


    },
    getters: {

    }
}) 